<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Rollover index API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'indices-rollover-index.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/indices-rollover-index.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/indices-rollover-index.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/indices-rollover-index.html" rel="nofollow" target="_blank">../en/indices-rollover-index.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="indices.html">Index APIs</a></span>
»
<span class="breadcrumb-node">Rollover index API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="indices-refresh.html">« Refresh API</a>
</span>
<span class="next">
<a href="indices-shrink-index.html">Shrink index API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="indices-rollover-index"></a>Rollover index API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h2>
</div></div></div>

<p>Assigns an <a class="xref" href="indices-aliases.html" title="Update index alias API">index alias</a> to a new index
when the alias’s existing index meets a condition you provide.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /alias1/_rollover/twitter
{
  "conditions": {
    "max_age":   "7d",
    "max_docs":  1000,
    "max_size": "5gb"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1715.console"></div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="rollover-index-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">POST /&lt;alias&gt;/_rollover/&lt;target-index&gt;</code></p>
<p><code class="literal">POST /&lt;alias&gt;/_rollover/</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="rollover-index-api-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The rollover index API rolls an <a class="xref" href="indices-aliases.html" title="Update index alias API">alias</a> to a new index when
the existing index meets a condition you provide. You can use this API to retire
an index that becomes too large or too old.</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>To roll over an index, a condition must be met <span class="strong strong"><strong>when you call the API</strong></span>.
Elasticsearch does not monitor the index after you receive an API response. To
automatically roll over indices when a condition is met, you can use Elasticsearch’s
<a class="xref" href="index-lifecycle-management.html" title="ILM: Manage the index lifecycle">index lifecycle management (ILM) policies</a>.</p>
</div>
</div>
<p>The rollover index API accepts a single alias name
and a list of <code class="literal">conditions</code>.</p>
<p>If the specified alias points to a single index,
the rollover request:</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
Creates a new index
</li>
<li class="listitem">
Adds the alias to the new index
</li>
<li class="listitem">
Removes the alias from the original index
</li>
</ol>
</div>
<p>If the specified alias points to multiple indices,
one of these indices must have <code class="literal">is_write_index</code> set to <code class="literal">true</code>.
In this case,
the rollover request:</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
Creates a new index
</li>
<li class="listitem">
Sets <code class="literal">is_write_index</code> to <code class="literal">true</code> for the new index
</li>
<li class="listitem">
Sets <code class="literal">is_write_index</code> to <code class="literal">false</code> for the original index
</li>
</ol>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="rollover-wait-active-shards"></a>Wait for active shards<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Because the rollover operation creates a new index to rollover to, the
<a class="xref" href="indices-create-index.html#create-index-wait-for-active-shards" title="Wait For active shards"><code class="literal">wait_for_active_shards</code></a> setting on
index creation applies to the rollover action.</p>
</div>

</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="rollover-index-api-path-params"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;alias&gt;</code>
</span>
</dt>
<dd>
(Required, string)
Name of the existing index alias
to assign to the target index.
</dd>
<dt>
<span class="term">
<code class="literal">&lt;target-index&gt;</code>
</span>
</dt>
<dd>
<p>(Optional*, string)
Name of the target index to create and assign the index alias.</p>
<p>Index names must meet the following criteria:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Lowercase only
</li>
<li class="listitem">
Cannot include <code class="literal">\</code>, <code class="literal">/</code>, <code class="literal">*</code>, <code class="literal">?</code>, <code class="literal">"</code>, <code class="literal">&lt;</code>, <code class="literal">&gt;</code>, <code class="literal">|</code>, ` ` (space character), <code class="literal">,</code>, <code class="literal">#</code>
</li>
<li class="listitem">
Indices prior to 7.0 could contain a colon (<code class="literal">:</code>), but that’s been deprecated and won’t be supported in 7.0+
</li>
<li class="listitem">
Cannot start with <code class="literal">-</code>, <code class="literal">_</code>, <code class="literal">+</code>
</li>
<li class="listitem">
Cannot be <code class="literal">.</code> or <code class="literal">..</code>
</li>
<li class="listitem">
Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster)
</li>
<li class="listitem">
Names starting with <code class="literal">.</code> are deprecated, except for <a class="xref" href="index-modules.html#index-hidden">hidden indices</a> and internal indices managed by plugins
</li>
</ul>
</div>
<p>*This parameter is not required
if the alias is assigned to an index name that ends with <code class="literal">-</code> and a number,
such as <code class="literal">logs-000001</code>.
In this case,
the name of the new index follows the same pattern,
incrementing the number.
For example,
<code class="literal">logs-000001</code> increments to <code class="literal">logs-000002</code>.
This number is zero-padded with a length of 6,
regardless of the prior index name.</p>
<p>If the existing index for the alias does not match this pattern,
this parameter is required.</p>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="rollover-index-api-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">dry_run</code>
</span>
</dt>
<dd>
(Optional, boolean)
If <code class="literal">true</code>,
the request checks whether the index matches provided conditions
but does not perform a rollover.
Defaults to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">include_type_name</code>
</span>
</dt>
<dd>
<span class="Admonishment Admonishment--change">
[<span class="Admonishment-version u-mono u-strikethrough">7.0.0</span>]
<span class="Admonishment-detail">
Deprecated in 7.0.0. Mapping types have been deprecated. See <a class="xref" href="removal-of-types.html" title="Removal of mapping types"><em>Removal of mapping types</em></a>.
</span>
</span>
(Optional, boolean) If <code class="literal">true</code>, a mapping type is expected in the body of
mappings. Defaults to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">wait_for_active_shards</code>
</span>
</dt>
<dd>
<p>(Optional, string) The number of shard copies that must be active before
proceeding with the operation. Set to <code class="literal">all</code> or any positive integer up
to the total number of shards in the index (<code class="literal">number_of_replicas+1</code>).
Default: 1, the primary shard.</p>
<p>See <a class="xref" href="docs-index_.html#index-wait-for-active-shards" title="Active shards">Active shards</a>.</p>
</dd>
<dt>
<span class="term">
<code class="literal">master_timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
<dt>
<span class="term">
<code class="literal">timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a response. If no response is received before the timeout expires, the request
fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="rollover-index-api-request-body"></a>Request body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">aliases</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="indices-aliases.html" title="Update index alias API">alias object</a>) Index aliases which include the
index. See <a class="xref" href="indices-aliases.html" title="Update index alias API">Update index alias</a>.
</dd>
<dt>
<span class="term">
<code class="literal">conditions</code>
</span>
</dt>
<dd>
<p>(Required, object)
Set of conditions the index alias’s existing index must met to roll over.</p>
<p>Parameters include:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">max_age</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>)
Maximum age of the index.
</dd>
<dt>
<span class="term">
<code class="literal">max_docs</code>
</span>
</dt>
<dd>
(Optional, integer)
Maximum number of documents in the index.
Documents added since the last refresh are not included in the document count.
The document count does <span class="strong strong"><strong>not</strong></span> include documents in replica shards.
</dd>
<dt>
<span class="term">
<code class="literal">max_size</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#byte-units" title="Byte size units">byte units</a>)
Maximum index size.
This is the total size of all primary shards in the index.
Replicas are not counted toward the maximum index size.
</dd>
</dl>
</div>
<div class="tip admon">
<div class="icon"></div>
<div class="admon_content">
<p>To see the current index size, use the <a class="xref" href="cat-indices.html" title="cat indices API">_cat indices</a> API.
The <code class="literal">pri.store.size</code> value shows the combined size of all primary shards.</p>
</div>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">mappings</code>
</span>
</dt>
<dd>
<p>(Optional, <a class="xref" href="mapping.html" title="Mapping">mapping object</a>) Mapping for fields in the index. If
specified, this mapping can include:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Field names
</li>
<li class="listitem">
<a class="xref" href="mapping-types.html" title="Field datatypes">Field datatypes</a>
</li>
<li class="listitem">
<a class="xref" href="mapping-params.html" title="Mapping parameters">Mapping parameters</a>
</li>
</ul>
</div>
<p>See <a class="xref" href="mapping.html" title="Mapping">Mapping</a>.</p>
</dd>
<dt>
<span class="term">
<code class="literal">settings</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="index-modules.html#index-modules-settings" title="Index Settings">index setting object</a>) Configuration
options for the index. See <a class="xref" href="index-modules.html#index-modules-settings" title="Index Settings">Index Settings</a>.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="rollover-index-api-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="rollover-index-basic-ex"></a>Basic example<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h4>
</div></div></div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /logs-000001 <a id="CO572-1"></a><i class="conum" data-value="1"></i>
{
  "aliases": {
    "logs_write": {}
  }
}

# Add &gt; 1000 documents to logs-000001

POST /logs_write/_rollover <a id="CO572-2"></a><i class="conum" data-value="2"></i>
{
  "conditions": {
    "max_age":   "7d",
    "max_docs":  1000,
    "max_size":  "5gb"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1716.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO572-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>Creates an index called <code class="literal">logs-0000001</code> with the alias <code class="literal">logs_write</code>.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO572-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>If the index pointed to by <code class="literal">logs_write</code> was created 7 or more days ago, or
contains 1,000 or more documents, or has an index size at least around 5GB, then the <code class="literal">logs-000002</code> index is created
and the <code class="literal">logs_write</code> alias is updated to point to <code class="literal">logs-000002</code>.</p>
</td>
</tr>
</table>
</div>
<p>The API returns the following response:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "acknowledged": true,
  "shards_acknowledged": true,
  "old_index": "logs-000001",
  "new_index": "logs-000002",
  "rolled_over": true, <a id="CO573-1"></a><i class="conum" data-value="1"></i>
  "dry_run": false, <a id="CO573-2"></a><i class="conum" data-value="2"></i>
  "conditions": { <a id="CO573-3"></a><i class="conum" data-value="3"></i>
    "[max_age: 7d]": false,
    "[max_docs: 1000]": true,
    "[max_size: 5gb]": false,
  }
}</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO573-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>Whether the index was rolled over.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO573-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>Whether the rollover was dry run.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO573-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>The result of each condition.</p>
</td>
</tr>
</table>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="rollover-index-settings-ex"></a>Specify settings for the target index<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The settings, mappings, and aliases for the new index are taken from any
matching <a class="xref" href="indices-templates.html" title="Put index template API">index templates</a>. Additionally, you can specify
<code class="literal">settings</code>, <code class="literal">mappings</code>, and <code class="literal">aliases</code> in the body of the request, just like the
<a class="xref" href="indices-create-index.html" title="Create index API">create index</a> API. Values specified in the request
override any values set in matching index templates. For example, the following
<code class="literal">rollover</code> request overrides the <code class="literal">index.number_of_shards</code> setting:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /logs-000001
{
  "aliases": {
    "logs_write": {}
  }
}

POST /logs_write/_rollover
{
  "conditions" : {
    "max_age": "7d",
    "max_docs": 1000,
    "max_size": "5gb"
  },
  "settings": {
    "index.number_of_shards": 2
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1717.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="rollover-index-specify-index-ex"></a>Specify a target index name<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h4>
</div></div></div>
<p>If the name of the existing index ends with <code class="literal">-</code> and a number — e.g.
<code class="literal">logs-000001</code> — then the name of the new index will follow the same pattern,
incrementing the number (<code class="literal">logs-000002</code>). The number is zero-padded with a length
of 6, regardless of the old index name.</p>
<p>If the old name doesn’t match this pattern then you must specify the name for
the new index as follows:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /my_alias/_rollover/my_new_index_name
{
  "conditions": {
    "max_age":   "7d",
    "max_docs":  1000,
    "max_size": "5gb"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1718.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_using_date_math_with_the_rollover_api"></a>Use date math with a rollover<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h4>
</div></div></div>
<p>It can be useful to use <a class="xref" href="date-math-index-names.html" title="Date math support in index names">date math</a> to name the
rollover index according to the date that the index rolled over, e.g.
<code class="literal">logstash-2016.02.03</code>.  The rollover API supports date math, but requires the
index name to end with a dash followed by a number, e.g.
<code class="literal">logstash-2016.02.03-1</code> which is incremented every time the index is rolled
over. For instance:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console"># PUT /&lt;logs-{now/d}-1&gt; with URI encoding:
PUT /%3Clogs-%7Bnow%2Fd%7D-1%3E <a id="CO574-1"></a><i class="conum" data-value="1"></i>
{
  "aliases": {
    "logs_write": {}
  }
}

PUT logs_write/_doc/1
{
  "message": "a dummy log"
}

POST logs_write/_refresh

# Wait for a day to pass

POST /logs_write/_rollover <a id="CO574-2"></a><i class="conum" data-value="2"></i>
{
  "conditions": {
    "max_docs":   "1"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1719.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO574-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>Creates an index named with today’s date (e.g.) <code class="literal">logs-2016.10.31-1</code></p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO574-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>Rolls over to a new index with today’s date, e.g. <code class="literal">logs-2016.10.31-000002</code> if run immediately, or <code class="literal">logs-2016.11.01-000002</code> if run after 24 hours</p>
</td>
</tr>
</table>
</div>
<p>These indices can then be referenced as described in the
<a class="xref" href="date-math-index-names.html" title="Date math support in index names">date math documentation</a>.  For example, to search
over indices created in the last three days, you could do the following:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console"># GET /&lt;logs-{now/d}-*&gt;,&lt;logs-{now/d-1d}-*&gt;,&lt;logs-{now/d-2d}-*&gt;/_search
GET /%3Clogs-%7Bnow%2Fd%7D-*%3E%2C%3Clogs-%7Bnow%2Fd-1d%7D-*%3E%2C%3Clogs-%7Bnow%2Fd-2d%7D-*%3E/_search</pre>
</div>
<div class="console_widget" data-snippet="snippets/1720.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="rollover-index-api-dry-run-ex"></a>Dry run<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The rollover API supports <code class="literal">dry_run</code> mode, where request conditions can be
checked without performing the actual rollover.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /logs_write/_rollover?dry_run
{
  "conditions" : {
    "max_age": "7d",
    "max_docs": 1000,
    "max_size": "5gb"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1721.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="indices-rollover-is-write-index"></a>Roll over a write index<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/rollover-index.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The rollover alias when rolling over a write index that has <code class="literal">is_write_index</code> explicitly set to <code class="literal">true</code> is not
swapped during rollover actions. Since having an alias point to multiple indices is ambiguous in distinguishing
which is the correct write index to roll over, it is not valid to rollover an alias that points to multiple indices.
For this reason, the default behavior is to swap which index is being pointed to by the write-oriented alias. This
was <code class="literal">logs_write</code> in some of the above examples. Since setting <code class="literal">is_write_index</code> enables an alias to point to multiple indices
while also being explicit as to which is the write index that rollover should target, removing the alias from the rolled over
index is not necessary. This simplifies things by allowing for one alias to behave both as the write and read aliases for
indices that are being managed with Rollover.</p>
<p>Look at the behavior of the aliases in the following example where <code class="literal">is_write_index</code> is set on the rolled over index.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT my_logs_index-000001
{
  "aliases": {
    "logs": { "is_write_index": true } <a id="CO575-1"></a><i class="conum" data-value="1"></i>
  }
}

PUT logs/_doc/1
{
  "message": "a dummy log"
}

POST logs/_refresh

POST /logs/_rollover
{
  "conditions": {
    "max_docs":   "1"
  }
}

PUT logs/_doc/2 <a id="CO575-2"></a><i class="conum" data-value="2"></i>
{
  "message": "a newer log"
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1722.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO575-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>configures <code class="literal">my_logs_index</code> as the write index for the <code class="literal">logs</code> alias</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO575-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>newly indexed documents against the <code class="literal">logs</code> alias will write to the new index</p>
</td>
</tr>
</table>
</div>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "_index" : "my_logs_index-000002",
  "_type" : "_doc",
  "_id" : "2",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}</pre>
</div>
<p>After the rollover, the alias metadata for the two indices will have the <code class="literal">is_write_index</code> setting
reflect each index’s role, with the newly created index as the write index.</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "my_logs_index-000002": {
    "aliases": {
      "logs": { "is_write_index": true }
    }
  },
  "my_logs_index-000001": {
    "aliases": {
      "logs": { "is_write_index" : false }
    }
  }
}</pre>
</div>
</div>

</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="indices-refresh.html">« Refresh API</a>
</span>
<span class="next">
<a href="indices-shrink-index.html">Shrink index API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>